#! /usr/bin/env python3

import json

import requests
from jsonpath import jsonpath

url = 'https://www.zhipin.com/wapi/zpCommon/data/getSubwayByCity'
params = {"cityCode": 101280600}
response = requests.get(url, params=params)
doc = response.json()
#with open('subway.json', 'w', encoding='utf-8') as f:
#   json.dump(doc, f, ensure_ascii=False, indent=4, separators=(',', ':'))

# 获取所有地铁线（节点）
lines = jsonpath(doc, '$..subwayList[*]')
for line in lines:
    # 输出各地铁线名称）
    print(jsonpath(line, '$.name'))
    # 输出该线所有站点
    print(jsonpath(line, '$.subLevelModelList..name'))
    print()


